package mo.offer_special;

public class L089 {

    public int rob(int[] nums) {
        int n = nums.length;
        if (n == 1) {
            return nums[0];
        }
        if (n <= 2) {
            return Math.max(nums[0], nums[1]);
        }
        //代表最大值
        int[] total = new int[n];
        total[0] = nums[0];
        total[1] = Math.max(nums[0], nums[1]);

        for (int i = 2; i < n; i++) {
            total[i] = Math.max(total[i-2]+nums[i], total[i-1]);
        }

        return total[n-1];
    }


    public static void main(String[] args) {
        L089 test = new L089();
        System.out.println(test.rob(new int[]{2,7,9,3,1}));
    }
}
